package petstore.web.servlet.recommend;

import petstore.domain.Product;
import petstore.persistence.user.User;
import petstore.persistence.user.UserDAOImpl;
import petstore.service.CatalogService;

import java.util.ArrayList;
import java.util.List;

public class test {
    public static void main(String[] args) {
        CatalogService catalogService = new CatalogService();
        UserDAOImpl userDAO = new UserDAOImpl();
        User user = userDAO.FindUserByUser_id(1);
        double totalFenmu = user.getKey_bird() + user.getKey_bugcat() + user.getKey_cat() + user.getKey_cat() + user.getKey_dog();
        int numCat = Math.min((int)(user.getKey_cat() / totalFenmu * 6.0 + 0.5),6);
        int numDog = Math.min((int)(user.getKey_dog() / totalFenmu * 6.0 + 0.5),6);
        int numBird = Math.min((int)(user.getKey_bird() / totalFenmu * 6.0 + 0.5),6);
        int numPokemon = Math.min((int)(user.getKey_pokemon() / totalFenmu * 6.0 + 0.5),6);
        int numBugCat = Math.min((int)(user.getKey_bugcat() / totalFenmu * 6.0 + 0.5),6);
        List<Product> productListCat = catalogService.getProductListBycategoryId("cat");
        List<Product> productListDog = catalogService.getProductListBycategoryId("dog");
        List<Product> productListBird = catalogService.getProductListBycategoryId("bird");
        List<Product> productListPokemon = catalogService.getProductListBycategoryId("pokemon");
        List<Product> productListBugCat = catalogService.getProductListBycategoryId("bugCat");
        List<Product> productList = new ArrayList<>();
        for(int i = 0;i < Math.min(numCat,productListCat.size());++i) productList.add(productListCat.get(i));
        for(int i = 0;i < Math.min(numDog,productListDog.size());++i) productList.add(productListDog.get(i));
        for(int i = 0;i < Math.min(numBird,productListBird.size());++i) productList.add(productListBird.get(i));
        for(int i = 0;i < Math.min(numPokemon,productListPokemon.size());++i) productList.add(productListPokemon.get(i));
        for(int i = 0;i < Math.min(numBugCat,productListBugCat.size());++i) productList.add(productListBugCat.get(i));
        for(Product p : productList){
            System.out.println(p.getName());
        }
    }
}
